package cn.keepme.ep.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jweb.core.query.hibernate.qbc.CriteriaQuery;
import org.jweb.core.util.StringUtil;

import cn.keepme.ep.auth.transfer.vo.authen.UserCategoryTradeVO;
import cn.keepme.ep.auth.transfer.vo.authen.UserCategoryVO;
import cn.keepme.ep.common.entity.DictType;
import cn.keepme.ep.common.service.SysServiceI;
import cn.keepme.ep.member.entity.UserCategoryEntity;
import cn.keepme.ep.member.entity.UserCategoryTradeEntity;
import cn.keepme.ep.member.transfer.form.member.UserCategorySearchForm;
import cn.keepme.ep.member.transfer.form.member.UserCategoryTradeSearchForm;


public class CommonMethod {

	/**
	 * 获取临时用户
	 * @param userId
	 * @return
	 */
	public static List<UserCategoryTradeVO> getTmpUserInfo(SysServiceI sysService, String userId){
		//获交易类型取数据字典
		List<DictType> tradeTypeDictTypeList = sysService.findDict("custom");
		Map<String,DictType> tradeTypeDictTypeMap = new HashMap<String,DictType>();
		for(DictType d : tradeTypeDictTypeList){
			tradeTypeDictTypeMap.put(d.getTypecode(), d);
		}
		
		UserCategoryTradeSearchForm searchForm = new UserCategoryTradeSearchForm();
		searchForm.setUserId(userId);
//		searchForm.emptyValue2NullValue();
		CriteriaQuery cq = searchForm.getCriteriaQuery();
		List<UserCategoryTradeEntity> userCategoryList = sysService.list(cq);
		
		List<UserCategoryTradeVO> ulist = new ArrayList<UserCategoryTradeVO>();
		for(UserCategoryTradeEntity c : userCategoryList){
			UserCategoryTradeVO vo = new UserCategoryTradeVO();
			vo.setStatus(c.getTradeRoomIdStatus());
			vo.setCategoryId(c.getCategoryId());
			vo.setCode(c.getCategoryCode());
			vo.setRoomid(c.getTradeRoomId());
			String code = c.getCategoryCode();
			if(StringUtil.isNotEmpty(code)){
				DictType temp = tradeTypeDictTypeMap.get(code);
				if(temp != null){
					vo.setName(temp.getTypename());
				}
			}
			vo.setTmpUserId(c.getTmpUserId());
//			vo.setTradeid(c.getTradeId());
			vo.setTradename(c.getTradeName());
			ulist.add(vo);
		}
		
		return ulist;
		
	}
	
	
	/**
	 * 获取用户
	 * @param userId
	 * @return
	 */
	public static List<UserCategoryVO> getUserInfo(SysServiceI sysService, String userId){
		//获交易类型取数据字典
		List<DictType> tradeTypeDictTypeList = sysService.findDict("custom");
		Map<String,DictType> tradeTypeDictTypeMap = new HashMap<String,DictType>();
		for(DictType d : tradeTypeDictTypeList){
			tradeTypeDictTypeMap.put(d.getTypecode(), d);
		}
		
		UserCategorySearchForm searchForm = new UserCategorySearchForm();
		searchForm.setUserId(userId);
//		searchForm.emptyValue2NullValue();
		CriteriaQuery cq = searchForm.getCriteriaQuery();
		List<UserCategoryEntity> userCategoryList = sysService.list(cq);
		
		List<UserCategoryVO> ulist = new ArrayList<UserCategoryVO>();
		for(UserCategoryEntity c : userCategoryList){
			UserCategoryVO vo = new UserCategoryVO();
			vo.setStatus(c.getTradeRoomIdStatus());
			vo.setCategoryId(c.getCategoryId());
			vo.setCode(c.getCategoryCode());
			vo.setRoomid(c.getTradeRoomId());
			String code = c.getCategoryCode();
			if(StringUtil.isNotEmpty(code)){
				DictType temp = tradeTypeDictTypeMap.get(code);
				if(temp != null){
					vo.setName(temp.getTypename());
				}
			}
			vo.setTradeid(c.getTradeId());
			vo.setTradename(c.getTradeName());
			ulist.add(vo);
		}
		
		return ulist;
		
	}
	

}
